﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class _Login : Connect
    {
        public int Dangnhap(string user, string pass)
        {
            int flag = -1;
            SqlConnection con = getconnect();
            con.Open();
            string sql = "select * from Login where TenDangNhap='" + user + "'and MatKhau='" + pass + "' ";
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                reader.Read();
                bool isAdmin = reader.GetBoolean(2);
                if (isAdmin == true)
                {
                    flag = 1;
                }
                else
                {
                    flag = 0;
                }
            }
            cmd.Dispose();
            reader.Dispose();
            con.Close();
            return flag;

        }
    }
}
